﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace LOGIN
{
    public partial class Math : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] == null)
            {
                Response.Redirect("index.aspx");
            }
            else this.login.Text = "" + Session["name"].ToString() + "老师，你已经成功进入登录页面";

        }

        protected void exit_Click(object sender, EventArgs e)
        {

            Response.Redirect("index.aspx");
        }

        protected void update_Click(object sender, EventArgs e)
        {
            Response.Redirect("Change.aspx");
        }

        protected void text_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strSql = "SELECT   Question, A, B, C, D FROM      Test WHERE   (Remark = N'" + this.ddlSubject.Text + "题目1')";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    this.question1.Text = dr["question"].ToString();
                    this.A1.Text = dr["A"].ToString();
                    this.B1.Text = dr["B"].ToString();
                    this.C1.Text = dr["C"].ToString();
                    this.D1.Text = dr["D"].ToString();
                }
                dr.Close();
                string straaa = "SELECT   Question, A, B, C, D FROM      Test WHERE   (Remark = N'" + this.ddlSubject.Text + "题目2')";
                SqlCommand bbb = new SqlCommand(straaa, cn);
                SqlDataReader ccc = bbb.ExecuteReader();
                if (ccc.Read())
                {
                    this.question2.Text = ccc["question"].ToString();
                    this.A2.Text = ccc["A"].ToString();
                    this.B2.Text = ccc["B"].ToString();
                    this.C2.Text = ccc["C"].ToString();
                    this.D2.Text = ccc["D"].ToString();
                }
                this.lblInfo.Text = "";
                dr.Close();

            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void tittle_Click(object sender, EventArgs e)
        {
            Response.Redirect("update.aspx");
        }

        protected void information_Click(object sender, EventArgs e)
        {
            Response.Redirect("Information.aspx");
        }

        protected void mark_Click(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Add.aspx");
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112122;uid=2014112122;pwd=19950123";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string UserAnswer1 = Request.QueryString["UserAnswer"];
                if (A1.Checked)
                {
                    UserAnswer1 = "A";
                }
                else if (B1.Checked)
                {
                    UserAnswer1 = "B";
                }
                else if (C1.Checked) { UserAnswer1 = "C"; }
                else
                {
                    UserAnswer1 = "D";
                }
                string UserAnswer2 = Request.QueryString["UserAnswer"];
                if (A2.Checked)
                {
                    UserAnswer2 = "A";
                }
                else if (B2.Checked)
                {
                    UserAnswer2 = "B";
                }
                else if (C2.Checked) { UserAnswer2 = "C"; }
                else
                {
                    UserAnswer2 = "D";
                }
                //string strSql = "INSERT INTO Login (Name, Password, Number, Sex, College) VALUES   (N'" + this.TextBox1.Text + "', N'" + this.TextBox3.Text + "', N'" + this.TextBox4.Text + "',  N'" + sex + "',N'" + this.TextBox5.Text + "')";
                //this.lblInfo.Text = "第一题答案是：" + UserAnswer1 + "，第二题答案是：" + UserAnswer2;
                int num = 80;
                string a = "0", b = "0";
                string strsql1 = "SELECT   TureAnswer  FROM      Test  WHERE   (Remark = N'" + this.ddlSubject.Text + "题目1')";
                string strsql2 = "SELECT   TureAnswer  FROM      Test  WHERE   (Remark = N'" + this.ddlSubject.Text + "题目2')";
                SqlCommand cmd1 = new SqlCommand(strsql1, cn);
                SqlCommand cmd2 = new SqlCommand(strsql2, cn);
                a = cmd1.ExecuteScalar().ToString();
                b = cmd2.ExecuteScalar().ToString();
                if (a == UserAnswer1)
                {
                    num = num + 10;
                }
                if (b == UserAnswer2)
                {
                    num = num + 10;
                }
                //this.lblInfo.Text = num.ToString();
                string name;
                name = Session["name"].ToString();
                this.lblInfo.Text = "您的答案为：" + UserAnswer1 + UserAnswer2 + Environment.NewLine + "，正确答案为：" + a + b + "，您的得分为：" + num.ToString() + "分";

                string oo = "";
                if (ddlSubject.Text == "语文")
                {
                    oo = "Chinese_mark";
                }
                if (ddlSubject.Text == "数学")
                {
                    oo = "Math_mark";
                }
                if (ddlSubject.Text == "英语")
                {
                    oo = "English_mark";
                }
                string sql = "UPDATE  Login  SET     " + oo + " = N'" + num + "'  WHERE   (Name = N'" + name + "')";
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Theme"] = this.DropDownList1.SelectedValue.ToString();
        }

        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] != null)
                this.Theme = Session["Theme"].ToString();
        }


    }
}